package com.mercury.game.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mercury.game.entity.DialogCommend;
import com.mercury.game.service.DialogCommendChoiceService;
import com.mercury.game.service.DialogCommendService;
import com.mercury.util.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 童雅婷
 * @since 2021-11-25
 */
@RestController
@RequestMapping("/game/commend")
public class DialogCommendController {
    @Autowired
    private DialogCommendService commendService;

    @Autowired
    private DialogCommendChoiceService choiceService;

    @ApiOperation("开始对话的接口，type： 1每周推荐 2文章 3是咖啡")
    @GetMapping("/begin/{type}")
    public R startCommend(@PathVariable int type){
        QueryWrapper<DialogCommend> wrapper = new QueryWrapper<>();
        wrapper.eq("status",1);
        wrapper.eq("dialogue_type",type);
        DialogCommend commend = commendService.getOne(wrapper);
        return R.ok().data("commend",commend);
    }

    @ApiOperation("选择以后获得选项或者对话")
    @GetMapping("/content/{id}")
    public R commendContinue(@PathVariable int id){
        DialogCommend commend = commendService.getById(id);
        if(commend.getStatus() == 2) return R.ok().message("对话结束");
        List<DialogCommend> commendList = choiceService.getResponse(id);
        return R.ok().data("commend",commendList);
    }

}

